Skip to content

Fix macOS compatibility in tools/log.sh#741

Open
Kunal241207 wants to merge 2 commits intoprecice:developfrom
Kunal241207:fix-macos-log-sh
Open

Fix macOS compatibility in tools/log.sh#741
Kunal241207 wants to merge 2 commits intoprecice:developfrom
Kunal241207:fix-macos-log-sh

Conversation

@Kunal241207
Copy link

Summary

tools/log.sh used GNU-specific flags that are not available on macOS.

This change makes the script portable by:

  • Replacing date --rfc-email with a helper that falls back to a compatible date format when the flag is unavailable.
  • Replacing tee --append with the portable tee -a.

The behavior of the script remains the same, but it now works correctly on macOS systems.


Checklist:

  • I added a summary of any user-facing changes (compared to the last release) in the changelog-entries/<PRnumber>.md.
  • I will remember to squash-and-merge, providing a useful summary of the changes of this PR.

@PranjalManhgaye
Copy link
Contributor

PranjalManhgaye commented Mar 6, 2026

@Kunal241207 nice fix. two quick questions: (1) Was using date -u in the fallback intentional? on linux we get local time, so i was wondering if we’d want the same on macOS , (may be removing that -u) (2) One “Started on:” has two spaces after the colon and the other has one—was that on purpose? Just curious. thanks

@Kunal241207
Copy link
Author

Kunal241207 commented Mar 6, 2026

@PranjalManhgaye Good catch, thanks!

  1. The -u wasn’t intentional. You're right that date --rfc-email uses local time, so removing -u makes the fallback match the original behavior better.
  2. The spacing difference wasn’t intentional either. I’ll normalize it to a single space.

I've pushed the update.

@MakisH MakisH added GSoC Contributed in the context of the Google Summer of Code systemtests labels Mar 6, 2026
@MakisH
Copy link
Member

MakisH commented Mar 20, 2026

Ah, this has been in my list since longer, thanks!

Related issue: #601

Do you think this approach solves both?

@Kunal241207
Copy link
Author

This change makes the timestamp generation in tools/log.sh portable, so it avoids the --rfc-email failure reported in #601 when this script is used.
However, I haven't done a full sweep of the repository to check for other direct usages of date --rfc-email, so there may still be additional occurrences elsewhere.

Copy link
Member

@MakisH MakisH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had another look. Overall, this PR not there yet, but it can be improved.

There are no other places where this is used.


STARTDATE="$(date --rfc-email)"
rfc_email_date() {
date --rfc-email 2>/dev/null || date '+%a, %d %b %Y %H:%M:%S %z'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the 2>/dev/null? If there is an error, I would rather see it than get the script to fail silently.

export LOGFILE

STARTDATE="$(date --rfc-email)"
rfc_email_date() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rfc_email_date directly refers to the implementation options (--rfc-email), which is the non-portable part. A more general name would be better.


STARTDATE="$(date --rfc-email)"
rfc_email_date() {
date --rfc-email 2>/dev/null || date '+%a, %d %b %Y %H:%M:%S %z'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If --rfc-email is not portable, why provide an explicit format as fallback, instead of making the explicit format the only option? That should work on every system.

ENDTIME="$(date +%s)"
echo "Finished on: $ENDDATE" | tee --append "$LOGFILE" 2>&1
echo "Duration: $((ENDTIME-STARTTIME)) seconds (wall-clock time, including time waiting for participants)" | tee --append "$LOGFILE" 2>&1
echo "Finished on: $ENDDATE" | tee -a "$LOGFILE" 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with --apend? I used the verbose option for readability.

I don't have a macOS system to test on, but this page, for example, suggests that both are valid.

echo "Finished on: $ENDDATE" | tee --append "$LOGFILE" 2>&1
echo "Duration: $((ENDTIME-STARTTIME)) seconds (wall-clock time, including time waiting for participants)" | tee --append "$LOGFILE" 2>&1
echo "Finished on: $ENDDATE" | tee -a "$LOGFILE" 2>&1
echo "Duration: $((ENDTIME-STARTTIME)) seconds (wall-clock time, including time waiting for participants)" | tee -a "$LOGFILE" 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you post some example output from this script, to see the format and the computed time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GSoC Contributed in the context of the Google Summer of Code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants